<?php
require_once 'AbstractParseMessage.class.php';

class FunctionParseMessage extends AbstractParseMessage {

    public function reveive($title, $message) {
        // On ne fait pas de statistiques si on n'est pas dans une fonction
        if( $this->name === null and ! ($title === 'enterFunction' or $title === 'enterMethod')) return;

        switch( $title ) {
            case 'addComment':
                $this->addComment(intval($message));
                break;
            case 'addLines':
                $this->addLines();
                break;
            case 'addMethodTypeHint':
            case 'addFunctionTypeHint':
            case 'addStaticReference':
            case 'addNewClassReference':
            case 'addCatchClassReference':
                $this->addStatInArray('references', $message, $message);
                break;
            case 'enterMethod':
                $this->reset();
                $this->name = $message['method'];
                $this->setStatValue('declaration', $message['declaration']);
                $this->setStatValue('phpdoc', $message['phpdoc']);
                $this->setStatValue('parameters', $message['parameters']);
                $this->setStatValue('line', $message['line']);
                break;
            case 'enterFunction':
                $this->reset();
                $this->name = $message['function'];
                $this->setStatValue('phpdoc', $message['phpdoc']);
                $this->setStatValue('parameters', $message['parameters']);
                $this->setStatValue('line', $message['line']);
                break;
            case 'addCyclo':
                $this->incStats('cyclo', 1);
                break;
            case 'variableThis':
                $this->incStats('this',1);
                break;
            case 'variableSuperglobal':
                $this->incStats('superglobal',1);
                break;
            case 'leaveMethod':
                $this->sendMessage('methodStat', array('method' => $this->name, 'stats' => $this->stats));
                $this->reset();
                break;
            case 'leaveFunction':
                $this->sendMessage('functionStat', array('function' => $this->name, 'stats' => $this->stats));
                $this->reset();
                break;
            case 'variableLocal':
                foreach($this->stats['parameters'] as $prm) {
                    if( $prm['variable'] ===$message ) return;
                }
                $this->addStatInArray('local', $message, $message);
                break;
            case 'variableLocalAssign':
                foreach($this->stats['parameters'] as $prm) {
                    if( $prm['variable'] ===$message ) return;
                }
                $this->addStatInArray('localAssign', $message, $message);
                break;
        }
    }

}